package cn.lili.controller.feign;

import cn.lili.common.enums.PromotionTypeEnum;
import cn.lili.modules.goods.client.GoodsClient;
import cn.lili.modules.goods.entity.dto.GoodsSearchParams;
import cn.lili.modules.promotion.client.SeckillClient;
import cn.lili.modules.promotion.entity.dos.Seckill;
import cn.lili.modules.promotion.entity.dto.SeckillCheckDTO;
import cn.lili.modules.promotion.entity.dto.search.SeckillSearchParams;
import cn.lili.modules.promotion.service.SeckillApplyService;
import cn.lili.modules.promotion.service.SeckillService;
import cn.lili.modules.promotion.tools.PromotionTools;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author paulG
 * @since 2022/1/14
 **/
@RestController
@RequiredArgsConstructor
public class SeckillFeignController implements SeckillClient {

    private final SeckillService seckillService;

    private final SeckillApplyService seckillApplyService;

    @Override
    public boolean savePromotions(Seckill seckill) {
        return seckillService.savePromotions(seckill);
    }

    @Override
    public boolean generatorSeckill() {
        return seckillService.generatorSeckill();
    }

    /**
     * 根据条件查询秒杀活动
     *
     * @param searchParams 查询参数
     * @return 秒杀活动列表
     */
    @Override
    public List<Seckill> listFindAll(SeckillSearchParams searchParams) {
        return seckillService.listFindAll(searchParams);
    }

    @Override
    public List<Seckill> checkSeckillIsActive(SeckillCheckDTO seckillCheckDTO) {
        return seckillService.list(PromotionTools.checkActiveTime(seckillCheckDTO.getStartTime(), seckillCheckDTO.getEndTime(), PromotionTypeEnum.SECKILL, null, seckillCheckDTO.getActivityId()));
    }

    @Override
    public Boolean deleteSeckillGoods(SeckillSearchParams searchParams) {
        return seckillApplyService.remove(searchParams.queryWrapper());
    }
}
